﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace DAL.Translator
{
    /// <summary>
    /// Define Role Translator
    /// </summary>
    public class RoleTranslator
    {
        /// <summary>
        /// To Translate RoleDataEntity to RoleBusinessEntity
        /// </summary>
        /// <param name="roleDE"></param>
        /// <returns></returns>
        public static BLL.Role TranslateEntityToBusiness(DAL.Role roleDE)
        {
            BLL.Role roleBE = new BLL.Role();
            roleBE.RoleId = roleDE.RoleId;
            roleBE.RoleName = roleDE.RoleName;
            roleBE.Status = StatusTranslator.TranslateEntityToBusiness(roleDE.Status);
            roleBE.Authorities = new List<BLL.Authority>();
            if (roleDE.Authority != null)
            {
                foreach (DAL.Authority item in roleDE.Authority)
                    {
                        roleBE.Authorities.Add(AuthorityTranslator.TranslateEntityToBusiness(item));
                    }
                }
            
            return roleBE;
        }

        /// <summary>
        /// To Translate RoleBusinessEntity to RoleDataEntity
        /// </summary>
        /// <param name="roleBE"></param>
        /// <returns></returns>
        public static DAL.Role TranslateBusinessToEntity(BLL.Role roleBE)
        {
            DAL.Role roleDE = new DAL.Role();
            roleDE.RoleId = roleBE.RoleId;
            roleDE.RoleName = roleBE.RoleName;
            roleDE.Status = StatusTranslator.TranslateBusinessToEntity(roleBE.Status);
            roleDE.Authority = new System.Data.Objects.DataClasses.EntityCollection<Authority>();
            if (roleBE.Authorities != null)
            {
                foreach (BLL.Authority item in roleBE.Authorities)  
                    {
                        roleDE.Authority.Add(AuthorityTranslator.TranslateBusinessToEntity(item));
                    }
                }           
            return roleDE;
        }
    }

}
